<?php 
/**
 *   Joomdiet - administrator/components/views/recipecategory/tmpl/default.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2010 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

defined('_JEXEC') or die('Restricted access'); ?>
<?php jimport('joomla.html.pane'); ?>
<form action="index.php" method="post" name="adminForm">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
    <tr>
        <td valign="top">
            <fieldset class="adminform">
                <legend><?php echo JText::_('COM_JOOMDIET_EDIT_LEGEND'); ?></legend>
                <table class="adminform">
                    <tr>
                        <input type="hidden" name="recipecategory_id" id="recipecategory_id" value="<?php echo $this->row->id; ?>" />
                        <td width="100" align="right"><label for="recipecategory_name"><?php echo JText::_('COM_JOOMDIET_RECIPE_CATEGORY_NAME'); ?></label></td>
                        <td><input class="text_area" type="text" size="32" maxlength="140" name="recipecategory_name" id="recipecategory_name" value="<?php echo $this->row->name; ?>" /></td>
                    </tr>
                    <tr>
                        <td align="right"><label for="recipecategory_description"><?php echo JText::_('COM_JOOMDIET_RECIPE_CATEGORY_DESCRIPTION'); ?></label></td>
                        <td><?php // loading joomla editor
                            $editor =& JFactory::getEditor();
                            $params = array('smilies' => '0',
                                                'style' => '1',
                                                'layer' => '0',
                                                'table' => '0',
                                                'clear_entities' => '0');
                                echo $editor->display('recipecategory_description', $this->row->description, '600', '400', '40', '20', false, $params);
                        ?></td>
                    </tr>
                </table>
            </fieldset>
        </td>
        <td valign="top" width="320px" style="padding: 7px 0 0 5px">
            <?php
                $pane =& JPane::getInstance('sliders');
                echo $pane->startPane('pane');
                echo $pane->startPanel('Parent category', 'panel1');
            ?>
            <select style="width: 95%;" name="recipecategory_parent_category" id="recipecategory_parent_category" size="20" class="required mcat">
                <option value="0" <?php if ($this->row->parent_category) echo 'selected="selected"'; ?>>Root</option>
                <?php loadCategories($this->fcategories, 0, $this->row->parent_category); ?>
            </select>
            <?php echo $pane->endPanel(); ?>
            <?php echo $pane->endPane(); ?>
        </td>
    </tr>
</table>

<input type="hidden" name="option" value="com_joomdiet" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="controller" value="recipecategories" />

</form>

<?php function loadCategories($categories, $level, $selected) { ?>
    <?php foreach ($categories as $category): ?>
        <option value="<?php echo $category['data']->id; ?>"
            <?php if ($category['data']->id == $selected) { echo 'selected="selected"'; } ?>>
            <?php for($p=0; $p < $level; $p++) { echo "&nbsp;&nbsp;"; } ?>
            &nbsp;&nbsp;<?php echo $category['data']->name; ?>
        </option>
        <?php loadCategories($category['children'], $level+1, $selected); ?>
    <?php endforeach; ?>
<?php } ?>
